﻿using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;

namespace JWFW.DAL
{
    [Serializable]
    public class SimpleMySqlOP : BaseSimpleDBOP
    {
        public SimpleMySqlOP(string connectionString)
            : base(connectionString)
        {
            m_colQuoteF = "`";
            m_colQuoteB = "`";
        }


        protected override System.Data.IDbCommand CreateCommand()
        {
            return new MySqlCommand();
        }

        protected override System.Data.IDbDataParameter CreateDataParameter()
        {
            return new MySqlParameter();
        }

        protected override System.Data.Common.DbDataAdapter CreateDataAdapter()
        {
            return new MySqlDataAdapter();
        }

        public override EDBType DBType
        {
            get { return EDBType.SimpleMySql; }
        }

        public override System.Data.IDbConnection CreateInstance(string connStr)
        {
            return new MySqlConnection(connStr);            
        }

        public override bool Exist(string tableName, string condition, string transID)
        {
            bool exist = true;
            string sql = "SELECT * FROM " + this.GetCol(tableName) + condition + " limit 1";
            string result = this.ExecuteScalar(sql, transID);
            if (result == "")
            {
                exist = false;
            }
            return exist;
        }
    }
}
